<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ajax异步请求</title>
</head>
<body>
    <div id="demo">
        学习异步请求
    </div>
    <button onclick="getText()">点击进行异步请求</button>
    <script>
        function getText(){
            // 先敲定个异步
            //document.getElementById("demo").innerHTML = "同步修改"；
            //异步
            //setTimeout(()=> {
            //document.getElementById("demo").innerHTML = "异步修改"；
            //异步
            //},2000)
            var xtr =new XMLHttpRequest();

            xtr.open("GET","https://mock.apipost.cn/app/mock/project/a01ae067-dd87-4b24-a079-247ae486dcd7/address/list",true);
            xtr.send();

            xtr.onreadystatechange = function (){
                if(xtr.readyState == 4){
                    document.getElementById("demo").innerHTML = xtr.responseText;
                    //console.log(xtr.responseText);
                }
            }
        }
    </script>
</body>
</html>